﻿Public Class frmCargosvb 

    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            Modificar.Enabled = True
            Eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub
    Private Sub CargosBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CargosBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.CargosBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub frmCargosvb_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.horarios' table. You can move, or remove it, as needed.
        Me.HorariosTableAdapter.Fill(Me.DbFireAndIceDataSet.horarios)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.cargos' table. You can move, or remove it, as needed.
        Me.CargosTableAdapter.Fill(Me.DbFireAndIceDataSet.cargos)

    End Sub

    Private Sub guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles guardar.Click


        If DescripcionTextBox.Text.Length = 0 Then
            ErrorProvider1.SetError(DescripcionTextBox, "Debe ingresar una descripción")

            Return
        End If
        ErrorProvider1.SetError(DescripcionTextBox, Nothing)




        If SalariopropuestoTextBox.Text.Length = 0 Then
            ErrorProvider1.SetError(SalariopropuestoTextBox, "Debe ingresar una cantidad")
            Return
        End If
        ErrorProvider1.SetError(SalariopropuestoTextBox, Nothing)






        'If HoraentradaTimeEdit.Text.Length = 0 Then
        '    ErrorProvider1.SetError(HoraentradaTimeEdit, "Debe ingresar una hora de entrada")
        'End If

        'If HorasalidaTimeEdit.Text.Length = 0 Then
        '    ErrorProvider1.SetError(HorasalidaTimeEdit, "Debe ingresar una hora de salida")


        'If (SalariopropuestoTextBox.Text <> "") And (DescripcionTextBox.Text <> "") Then
        '    ErrorProvider1.SetError(ValorhoraextraTextBox, Nothing)
        '    ErrorProvider1.SetError(DescripcionTextBox, Nothing)
        '    ErrorProvider1.SetError(IdhorarioLookUpEdit, Nothing)
        '    ErrorProvider1.SetError(SalariopropuestoTextBox, Nothing)
        '    'ErrorProvider1.SetError(HoraentradaTimeEdit, Nothing)
        'ErrorProvider1.SetError(HorasalidaTimeEdit, Nothing)

        Try
            CargosBindingNavigatorSaveItem.PerformClick()
            Mostrar()

        Catch ex As Exception
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Error", "Nose pudo guardar el registro")
        End Try
     

        AlertControl1.AppearanceCaption.ForeColor = Color.Green
        AlertControl1.Show(Me, "Advertencia", "Se guardó el resgistro satisfactoriamente")
       

    End Sub

    Private Sub agregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()
    End Sub

    Private Sub modificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modificar.Click
   
        Mostrar()

    End Sub

    Private Sub eliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eliminar.Click
        Dim opcion2 As Integer
        opcion2 = MsgBox("¿Está seguro que desea eliminar el registro?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Eliminar registro")
        If opcion2 = vbYes Then
            Try
                CargosTableAdapter.DeleteQuery(IdcargoTextBox1.Text)
                Me.CargosTableAdapter.Fill(Me.DbFireAndIceDataSet.cargos)
            Catch ex As Exception
                MsgBox("Lo sentimos, el registro no puede ser eliminado ya que está relacionado con otras tablas", MsgBoxStyle.Critical, "Error")
            End Try


        End If
    End Sub

    Private Sub imprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imprimir.Click
        GridControl1.ShowPrintPreview()

    End Sub

    Private Sub cancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelar.Click
     
        ErrorProvider1.SetError(DescripcionTextBox, Nothing)
        ErrorProvider1.SetError(SalariopropuestoTextBox, Nothing)
        Mostrar()
    End Sub

    Private Sub SalariopropuestoTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        If Char.IsLetter(e.KeyChar) Then
            e.Handled = True
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Error", "Solo puede ingresar números")
            SalariopropuestoTextBox.Focus()

        ElseIf Char.IsSeparator(e.KeyChar) Then
            e.Handled = True
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Error", "No debe ingresar espacios")
            SalariopropuestoTextBox.Focus()

        Else
            e.Handled = False

        End If
    End Sub

 


 

  
End Class